<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="renderer" content="webkit"/>
  <meta name="force-rendering" content="webkit"/>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/>
  <title>新增网站</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.min.css">
  <link rel="stylesheet" href="/bower_components/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="/bower_components/Ionicons/css/ionicons.min.css">
  <link rel="stylesheet" href="/bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
  <link rel="stylesheet" href="/dist/css/AdminLTE.min.css">
  <link rel="stylesheet" href="/dist/css/skins/_all-skins.min.css">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->

  <!-- Google Font -->
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

  <!--头部-->
  <header id="headerDiv" class="main-header">
    <!--#include  file="header.html"-->
  </header>

  <!--左侧边栏 -->
  <aside id="sidebarDiv" class="main-sidebar">
    <!--#include  file="sidebar.html"-->
  </aside>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        <small>新建网站</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-gamepad"></i> 网站管理</a></li>
        <li><a href="javascript:goBack();">网站列表</a></li>
        <li><a href="javascript:void (0);">新建网站</a></li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="row">
        <div class="col-xs-12">
          <div class="box box-primary">
            <div class="box-header with-border">
              <h3 class="box-title">新增网站</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form id="dataForm" class="form-horizontal">
              <div class="box-body">

                <div class="form-group">
                  <label for="site_name" class="col-sm-2 control-label">网站名称</label>

                  <div class="col-sm-5">
                    <input type="text" name="site_name" maxlength="20" class="form-control" id="site_name">
                  </div>
                </div>
                <div class="form-group">
                  <label for="site_url" class="col-sm-2 control-label">网站域名</label>
                  <div class="col-sm-5">
                  <div class="input-group">
                    <span class="input-group-addon">http://</span>
                    <input id="site_url" type="text" name="site_url" maxlength="200" class="form-control">
                  </div>
                  </div>

                </div>

                <div class="form-group">
                  <label for="os_type" class="col-sm-2 control-label">终端类型</label>
                  <div class="col-sm-2">
                    <select id="os_type" onchange="isShow();"  class="form-control" name="os_type">
                      <option value="0">WAB</option>
                      <option value="1">APP</option>
                      <option value="2">小程序</option>
                    </select>
                  </div>
                </div>

                <div id="appkeyDiv" class="form-group" style="display: none;">
                  <label for="appkey" class="col-sm-2 control-label">APPKEY</label>

                  <div class="col-sm-5">
                    <input type="text" name="appkey" maxlength="50" class="form-control" id="appkey">
                  </div>
                </div>

                <div class="form-group">
                  <label for="site_type" class="col-sm-2 control-label">内容类型</label>
                  <div class="col-sm-2">
                    <select id="site_type"  class="form-control" name="site_type">
                      <option value="0">电影</option>
                      <option value="1">游戏</option>
                      <option value="2">工具</option>
                      <option value="3">小说</option>
                      <option value="4">图片</option>
                      <option value="5">生活服务</option>
                      <option value="6">教育</option>
                      <option value="7">健康</option>
                      <option value="8">新闻</option>
                    </select>
                  </div>
                </div>

                <div class="form-group">
                  <label for="day_num" class="col-sm-2 control-label">日访问量(IP)</label>
                  <div class="col-sm-2">
                    <input type="number" name="day_num" maxlength="20" class="form-control" id="day_num">
                  </div>
                </div>

              </div>


              <!-- /.box-body -->
              <div class="box-footer">
                <button type="button" onclick="goBack();" class="btn btn-default">取消</button>
                <button type="button" onclick="submitForm()" class="btn btn-primary">提交</button>
              </div>
              <!-- /.box-footer -->
            </form>
          </div>
        </div>
      </div>
    </section>
  </div>
  <!--底部-->
  <footer id="footerDiv" class="main-footer">
    <!--#include  file="footer.html"-->
  </footer>

  <!-- Control Sidebar -->
  <!-- /.control-sidebar -->
  <!-- Add the sidebar's background. This div must be placed
       immediately after the control sidebar -->
  <div class="control-sidebar-bg"></div>
</div>
<script src="/bower_components/jquery/dist/jquery.min.js"></script>
<script src="/bower_components/morris.js/morris.min.js"></script>
<script src="/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="/bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="/bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
<script src="/bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<script src="/bower_components/fastclick/lib/fastclick.js"></script>
<script src="/dist/js/adminlte.min.js"></script>

<script src="/dist/js/layer/layer.js"></script>
<script src="/dist/js/bootstrapValidator.min.js"></script>

<script>
    var flag=true;
    $(function () {
        isShow();
        //表单验证
        $('#dataForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                site_name: {
                    validators: {
                        notEmpty: {
                            message: '网站名称不能为空'
                        }
                    }
                },
                site_url: {
                    validators: {
                        notEmpty: {
                            message: '网站域名不能为空'
                        }
                    }
                },
                day_num: {
                    validators: {
                        notEmpty: {
                            message: '日访问量不能为空'
                        }
                    }
                }

            }
        });


    });
    function submitForm() {
        if(!flag){
            return;
        }

        $('#dataForm').bootstrapValidator('validate');

        if($("#dataForm").data("bootstrapValidator").isValid()){
            flag=false;
            let url="/lmgame/channel/saveSite";
            $.ajax({
                type : 'POST',
                url : url,
                data :$("#dataForm").serialize(),
                dataType : "json",
                success: function(data) {
                    if (data.code != 0) {
                        layer.msg(data.msg);
                    } else {
                        layer.msg('新建成功', {
                            icon: 1,
                            time: 1000 //3秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            flag=true;
                            window.location.href = "/pages/channel/siteList.html";
                        });
                    }
                },
                error:function (data) {
                    flag=true;
                }
            });
        }
    }

function isShow() {
        let osType=$("#os_type").val();
    if(osType==='1'){
        $("#appkeyDiv").show();
    }else {
        $("#appkeyDiv").hide();
    }
}
    function  goBack() {
        window.history.back(-1);
    }
</script>
</body>
</html>
